home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume27 / sfs / part20 < prev    next >
Encoding:
Text File  |  1991-12-27  |  55.2 KB  |  1,954 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i020:  sfs - Space Flight Simulator, Part20/21
  4. Message-ID: <1991Dec24.192021.21272@sparky.imd.sterling.com>
  5. X-Md4-Signature: 0244bac2db9285498be96ee343c681cc
  6. Date: Tue, 24 Dec 1991 19:20:21 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  10. Posting-number: Volume 27, Issue 20
  11. Archive-name: sfs/part20
  12. Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file sfs/sfs/sfsm.h continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 20; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping sfs/sfs/sfsm.h'
  32. else
  33. echo 'x - continuing file sfs/sfs/sfsm.h'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'sfs/sfs/sfsm.h' &&
  35. #define STAT_TITLE      "STATUS"
  36. #define SFSM_CPFI       "The current program file is:    %s; %s "
  37. #define SFSM_CPFX       "Current Program File "
  38. #define MM_TTL          " Main Menu "
  39. #define SFSM_SPF        "Select SFS Program File"
  40. #define MEMERR_ERR      "Cannot allocate memory for error message.\n"
  41. #define ERR_PROMPT      "ERROR:  %s; Do you want to continue? "
  42. #define ERRP_NO         "N - ABORT"
  43. #define ERRP_YES        "Y - Continue"
  44. #define ERR_MATH        "Mathematics error, %s"
  45. #define OM_TITLE        "Orbital Modeling Menu"
  46. #define SOP_TITLE       "Set Orbital Parameters"
  47. #define AP_TITLE        "Additional Parameters"
  48. #define OM_SPT          " Set program title [%s] "
  49. #define OM_SON          " Set current orbit Number [%d] "
  50. #define OM_SOP          " Set orbital parameters"
  51. #define OM_SIP          " Set insertion parameter [%ld seconds] "
  52. #define OM_SSP          " Set system parameters"
  53. #define OM_VCO          " View current orbit"
  54. #define OM_EXIT         " Exit from modeling"
  55. #define OM_TTL          "Orbital Modeling Menu"
  56. #define SPT_TITLE       "Set Program Title"
  57. #define SPT_LEGEND      "Please enter a new title for the program or RETURN to keep the old one."
  58. #define SPT_PROMPT      "Program Title:  "
  59. #define SON_TITLE       "Set Current Orbit Number"
  60. #define SON_LEGEND      "Enter an Orbit number between 1 and %d"
  61. #define SON_PROMPT      "Number of Orbit:   "
  62. #define SIP_TITLE       "Set Insertion Point "
  63. #define SIP_LEGEND      "The insertion point is the moment in the orbit when insertion occurs.  Enter the insertion point in seconds."
  64. #define SIP_PROMPT      "Insertion:   "
  65. #define OM_SF           "Please indicate whether you want to save the parameters you have entered.  Enter Y or N"
  66. #define SF_TITLE        "Set Filename to Save Parameters"
  67. #define SF_LEGEND       "Please enter a filename for the new parameters to be saved, or enter <RETURN> to use the current name (old contents will be destroyed)."
  68. #define SF_PROMPT       "Filename:  "
  69. #define MM_MEMERR       "Cannot allocate memory for Modeling Menu "
  70. #define OPM_MEMERR      "Cannot allocate memory for Orbital Parameters Menu "
  71. #define APM_MEMERR      "Cannot allocate memory for Auxiliary Parameters Menu "
  72. #define SPM_MEMERR      "Cannot allocate memory for System Parameters Menu "
  73. #define SSP_TF          " Time Factor [%ld x real time]"
  74. #define SSP_UI          " Screen Update Interval [%ld seconds]"
  75. #define SSP_TPL         " Trig Precision Level [%d]"
  76. #define SSP_EXIT        " Exit to Main Orbital Modeling Menu"
  77. #define SSP_TITLE       "Set System Parameters"
  78. #define SOP_SOF         " Set orbital focus [%s] "
  79. #define SOP_SN          " Name of Spacecraft/Orbit [%s]"
  80. #define SOP_SDF         " Surface Datafile [%s]"
  81. #define SOP_PRI         " Periapsis [%.2lf km]"
  82. #define SOP_APO         " Apoapsis [%.2lf km]"
  83. #define SOP_INC         " Inclination [%.2lf deg]"
  84. #define SOP_ARP         " Argument of the Periapsis [%.2lf deg]"
  85. #define SOP_LAN         " Longitude of Asc. Node [%.2lf deg]"
  86. #define SOP_EXIT        " Exit to Main Orbital Modeling Menu"
  87. #define SOP_TITLE2      "Set Parameters for Orbit %d"
  88. #define SOF_TITLE       "Select SFS Focal Data File"
  89. #define SN_TITLE        "Set Orbit/Spacecraft Name for Orbit %d"
  90. #define SN_PROMPT       "Name of Orbit/Spacecraft:   "
  91. #define SN_LEGEND       "Enter a name for the orbit or the spacecraft."
  92. #define SDF_TITLE       "Select Surface Data File"
  93. #define PRI_TITLE       "Set Periapsis for Orbit %d"
  94. #define PRI_LEGEND      "The periapsis is the lowest point in an orbit.  Enter the periapsis in kilometers (must be less than %.1lf km). "
  95. #define PRI_PROMPT      "Periapsis:   "
  96. #define APO_TITLE       "Set Apoapsis for Orbit %d"
  97. #define APO_LEGEND      "The apoapsis is the highest point in an orbit.  Enter the apoapsis in kilometers (must be greater than %.1lf km). "
  98. #define APO_PROMPT      "Apoapsis:  "
  99. #define INC_TITLE       "Set Inclination for Orbit %d"
  100. #define INC_LEGEND      "The inclination describes the angle at which the orbit is inclined with relation to the equator of the orbital focus.  Enter the inclination in degrees between %.1lf and %.1lf. "
  101. #define INC_PROMPT      "Inclination:   "
  102. #define ARP_TITLE       "Set Argument of the Periapsis for Orbit %d"
  103. #define ARP_LEGEND      "The argument of the periapsis describes the point in the orbit at which periapsis occurs, measured from the point of the ascending node.  Enter the argument of the periapsis in degrees between %.1lf and %.1lf."
  104. #define ARP_PROMPT      "Argument of Periapsis:  "
  105. #define LAN_TITLE       "Set the Longitude of the Ascending Node for Orbit %d"
  106. #define LAN_LEGEND      "The longitude of the ascending node describes the point in the first orbit at which the spacecraft crosses the equator heading northward.  Enter the longitude of the ascending node in degrees between %.1lf and %.1lf."
  107. #define LAN_PROMPT      "Longitude of Ascending Node:  "
  108. #define AP_MAS          " Mass of the Orbital Focus [%.2le gr]"
  109. #define AP_RAD          " Radius of the Orbital Focus [%.0lf km]"
  110. #define AP_SID          " Sidereal Period [%.0lf seconds]"
  111. #define AP_SMI          " Semiminor Axis [%.2lf km]"
  112. #define AP_ECC          " Eccentricity [%.6lf]"
  113. #define AP_PER          " Orbital Period [%.2lf seconds; %.2lf days]"
  114. #define AP_TITLE2       "Additional Parameters for Orbit %d"
  115. #define GETYN_NO        " NO "
  116. #define GETYN_YES       " YES "
  117. #define SPW_MEMERR      "Cannot allocate memory for set parameters window "
  118. #define MES_MM          "Main Menu"
  119. #define MES_OM          "Orbital Modeling Menu"
  120. #define MES_SP          "Set Parameters Menu"
  121. #define MES_SSP         "Set System Parameters Menu"
  122. #endif
  123. X
  124. extern  double  get_double();
  125. extern  long    get_long();
  126. X
  127. extern  char    init_buffer[ 128 ]; /* Buffer for initialization
  128. X                    of focal data            */
  129. extern  char    sfs_tbuf[ 512 ];
  130. X
  131. extern  int     sfs_curorbit;
  132. extern  long    sfs_insertion;
  133. extern  long    sfs_inc;          
  134. extern    long    sfs_tfactor;    /* time factor            */
  135. extern  char    sfs_prname[ 128 ];
  136. extern    int    sfs_go;
  137. extern  double  sfs_size;       /* size factor for particular screen    */
  138. extern    double     sin_table[ 91 ];
  139. X
  140. extern  int      display;
  141. extern    int      _xy_array[ 20 ];
  142. extern    int      work_in[ 21 ];
  143. extern  int    work_out[ 57 ];
  144. extern  char    sfs_program[ 36  ];
  145. extern  struct  uiwindow *set_window;
  146. extern  struct  menu_box w1, w2, w3, w4;
  147. extern    int      sp_x1, sp_y1, sp_x2, sp_y2;
  148. extern struct dir_ent *d_entries[ MAX_ENTRIES ];
  149. extern char *d_titles[ MAX_ENTRIES ];
  150. X
  151. X
  152. /***    Colors */
  153. X
  154. extern    int    cl_mback;        /* Main background color    */
  155. extern    int    cl_mfore;        /* Main foreground color    */
  156. extern    int    cl_marker;        /* Color for prompt markers    */
  157. extern    int    cl_grid;        /* Color for planetary grid    */
  158. extern    int    cl_surface;        /* Color for planetary surface    */
  159. extern    int    cl_orbits[ 6 ];        /* Colors for different orbits    */
  160. X
  161. extern struct  uiwindow *main_window;          /* structure for main window    */
  162. extern struct  uiwindow *logo_window;
  163. X
  164. extern int     stat_y1;                        /* line for status display      */
  165. extern int     stat_y2;                        /* top of status display        */
  166. extern int     stat_x1;                        /* column for status display    */
  167. extern int     stat_x2;                        /* max col for status display   */
  168. X
  169. SHAR_EOF
  170. echo 'File sfs/sfs/sfsm.h is complete' &&
  171. chmod 0644 sfs/sfs/sfsm.h ||
  172. echo 'restore of sfs/sfs/sfsm.h failed'
  173. Wc_c="`wc -c < 'sfs/sfs/sfsm.h'`"
  174. test 10462 -eq "$Wc_c" ||
  175.     echo 'sfs/sfs/sfsm.h: original size 10462, current size' "$Wc_c"
  176. rm -f _shar_wnt_.tmp
  177. fi
  178. # ============= sfs/sfs/sfsm.mak ==============
  179. if test -f 'sfs/sfs/sfsm.mak' -a X"$1" != X"-c"; then
  180.     echo 'x - skipping sfs/sfs/sfsm.mak (File already exists)'
  181.     rm -f _shar_wnt_.tmp
  182. else
  183. > _shar_wnt_.tmp
  184. echo 'x - extracting sfs/sfs/sfsm.mak (Text)'
  185. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm.mak' &&
  186. PROJ    =SFSM
  187. DEBUG    =0
  188. CC    =qcl
  189. CFLAGS_G        = /AL /W1 /Ze /DDEBUG /I..\..\include
  190. CFLAGS_D    = /Zi /Zr /Gi$(PROJ).mdt /Od 
  191. CFLAGS_R    = /O /Ot /DNDEBUG 
  192. CFLAGS    =$(CFLAGS_G) $(CFLAGS_R)
  193. LFLAGS_G    = /CP:0xffff /NOI /NOE /SE:0x80 /ST:0x800 
  194. LFLAGS_D    = /CO /M /INCR 
  195. LFLAGS_R    = 
  196. LFLAGS    =$(LFLAGS_G) $(LFLAGS_R)
  197. RUNFLAGS    =
  198. OBJS_EXT =      ..\..\lib\dr_ibmpc.obj ..\..\lib\gr_ibmpc.obj ..\..\lib\kb_ibmpc.obj ..\..\lib\ui_boxes.obj \
  199. X    ..\..\lib\ui_dial.obj ..\..\lib\ui_gets.obj ..\..\lib\ui_init.obj ..\..\lib\ui_list.obj \
  200. X    ..\..\lib\ui_text.obj ..\..\lib\ui_pbm.obj
  201. LIBS_EXT =     
  202. X
  203. all:    $(PROJ).exe
  204. X
  205. sfsm_om.obj:    sfsm_om.c
  206. X
  207. sfsm.obj:    sfsm.c
  208. X
  209. as_orbit.obj:    ..\as\as_orbit.c
  210. X
  211. as_spj.obj:    ..\as\as_spj.c
  212. X
  213. as_vpt.obj:    ..\as\as_vpt.c
  214. X
  215. sfs_pe.obj:    sfs_pe.c
  216. X
  217. sfs_pr.obj:    sfs_pr.c
  218. X
  219. as_focus.obj:    ..\as\as_focus.c
  220. X
  221. $(PROJ).exe:    sfsm_om.obj sfsm.obj as_orbit.obj as_spj.obj as_vpt.obj sfs_pe.obj sfs_pr.obj \
  222. X    as_focus.obj $(OBJS_EXT)
  223. X    echo >NUL @<<$(PROJ).crf
  224. sfsm_om.obj +
  225. sfsm.obj +
  226. as_orbit.obj +
  227. as_spj.obj +
  228. as_vpt.obj +
  229. sfs_pe.obj +
  230. sfs_pr.obj +
  231. as_focus.obj +
  232. $(OBJS_EXT)
  233. $(PROJ).exe
  234. X
  235. $(LIBS_EXT);
  236. <<
  237. X    link $(LFLAGS) @$(PROJ).crf
  238. X
  239. run: $(PROJ).exe
  240. X    $(PROJ) $(RUNFLAGS)
  241. X
  242. SHAR_EOF
  243. chmod 0644 sfs/sfs/sfsm.mak ||
  244. echo 'restore of sfs/sfs/sfsm.mak failed'
  245. Wc_c="`wc -c < 'sfs/sfs/sfsm.mak'`"
  246. test 1158 -eq "$Wc_c" ||
  247.     echo 'sfs/sfs/sfsm.mak: original size 1158, current size' "$Wc_c"
  248. rm -f _shar_wnt_.tmp
  249. fi
  250. # ============= sfs/sfs/sfsm_n.mak ==============
  251. if test -f 'sfs/sfs/sfsm_n.mak' -a X"$1" != X"-c"; then
  252.     echo 'x - skipping sfs/sfs/sfsm_n.mak (File already exists)'
  253.     rm -f _shar_wnt_.tmp
  254. else
  255. > _shar_wnt_.tmp
  256. echo 'x - extracting sfs/sfs/sfsm_n.mak (Text)'
  257. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm_n.mak' &&
  258. PROJ    =SFSM
  259. DEBUG    =0
  260. LIBDIR  = ..\..\lib
  261. CC    =qcl
  262. CFLAGS_G        = /AL /W1 /Ze /DDEBUG /I..\..\include
  263. CFLAGS_D    = /Zi /Zr /Gi$(PROJ).mdt /Od 
  264. CFLAGS_R    = /O /Ot /DNDEBUG 
  265. CFLAGS    =$(CFLAGS_G) $(CFLAGS_R)
  266. LFLAGS_G    = /CP:0xffff /NOI /NOE /SE:0x80 /ST:0x800 
  267. LFLAGS_D    = /CO /M /INCR 
  268. LFLAGS_R    = 
  269. LFLAGS    =$(LFLAGS_G) $(LFLAGS_R)
  270. RUNFLAGS    =
  271. OBJS_A  =       $(LIBDIR)\dr_ibmpc.obj $(LIBDIR)\gr_ibmpc.obj $(LIBDIR)\kb_ibmpc.obj $(LIBDIR)\ui_boxes.obj
  272. OBJS_B  =       $(LIBDIR)\ui_dial.obj $(LIBDIR)\ui_gets.obj $(LIBDIR)\ui_init.obj
  273. OBJS_C  =       $(LIBDIR)\ui_list.obj $(LIBDIR)\ui_text.obj $(LIBDIR)\ui_pbm.obj
  274. LIBS_EXT =     
  275. X
  276. all:    $(PROJ).exe
  277. X
  278. sfsm_om.obj:    sfsm_om.c
  279. X
  280. sfsm.obj:    sfsm.c
  281. X
  282. sfs_pe.obj:    sfs_pe.c
  283. X
  284. sfs_pr.obj:    sfs_pr.c
  285. X
  286. as_orbit.obj:   
  287. X                $(CC) $(CFLAGS) -c ..\as\as_orbit.c
  288. X
  289. as_spj.obj:     
  290. X                $(CC) $(CFLAGS) -c ..\as\as_spj.c
  291. X
  292. as_vpt.obj:     
  293. X                $(CC) $(CFLAGS) -c ..\as\as_vpt.c
  294. X
  295. as_focus.obj:   
  296. X                $(CC) $(CFLAGS) -c ..\as\as_focus.c
  297. X
  298. $(PROJ).exe:    sfsm_om.obj sfsm.obj as_orbit.obj as_spj.obj \
  299. X        as_vpt.obj sfs_pe.obj sfs_pr.obj \
  300. X    as_focus.obj \
  301. X        $(OBJS_A) \
  302. X        $(OBJS_B) \
  303. X        $(OBJS_C)
  304. X    echo >NUL @<<$(PROJ).crf
  305. sfsm_om.obj +
  306. sfsm.obj +
  307. as_orbit.obj +
  308. as_spj.obj +
  309. as_vpt.obj +
  310. sfs_pe.obj +
  311. sfs_pr.obj +
  312. as_focus.obj +
  313. $(OBJS_A) +
  314. $(OBJS_B) +
  315. $(OBJS_C)
  316. $(PROJ).exe
  317. X
  318. $(LIBS_EXT);
  319. <<
  320. X    link $(LFLAGS) @$(PROJ).crf
  321. X
  322. run: $(PROJ).exe
  323. X    $(PROJ) $(RUNFLAGS)
  324. X
  325. SHAR_EOF
  326. chmod 0644 sfs/sfs/sfsm_n.mak ||
  327. echo 'restore of sfs/sfs/sfsm_n.mak failed'
  328. Wc_c="`wc -c < 'sfs/sfs/sfsm_n.mak'`"
  329. test 1443 -eq "$Wc_c" ||
  330.     echo 'sfs/sfs/sfsm_n.mak: original size 1443, current size' "$Wc_c"
  331. rm -f _shar_wnt_.tmp
  332. fi
  333. # ============= sfs/sfs/sfsm_om.c ==============
  334. if test -f 'sfs/sfs/sfsm_om.c' -a X"$1" != X"-c"; then
  335.     echo 'x - skipping sfs/sfs/sfsm_om.c (File already exists)'
  336.     rm -f _shar_wnt_.tmp
  337. else
  338. > _shar_wnt_.tmp
  339. echo 'x - extracting sfs/sfs/sfsm_om.c (Text)'
  340. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm_om.c' &&
  341. /***************************************************************
  342. X
  343. X    sfsm_om.c    Orbital Modeling routines for
  344. X            Space Flight Simulator,
  345. X            Modeling Module
  346. X
  347. X            Copyright (c) 1991, Ted A. Campbell
  348. X
  349. X            Bywater Software
  350. X            P. O. Box 4023 
  351. X            Duke Station 
  352. X            Durham, NC  27706
  353. X
  354. X            email: tcamp@hercules.acpub.duke.edu
  355. X
  356. X    Copyright and Permissions Information:
  357. X
  358. X    All U.S. and international copyrights are claimed by the
  359. X    author. The author grants permission to use this code
  360. X    and software based on it under the following conditions:
  361. X    (a) in general, the code and software based upon it may be 
  362. X    used by individuals and by non-profit organizations; (b) it
  363. X    may also be utilized by governmental agencies in any country,
  364. X    with the exception of military agencies; (c) the code and/or
  365. X    software based upon it may not be sold for a profit without
  366. X    an explicit and specific permission from the author, except
  367. X    that a minimal fee may be charged for media on which it is
  368. X    copied, and for copying and handling; (d) the code must be 
  369. X    distributed in the form in which it has been released by the
  370. X    author; and (e) the code and software based upon it may not 
  371. X    be used for illegal activities. 
  372. X
  373. ***************************************************************/
  374. X
  375. #include "stdio.h"
  376. #include "sfsm.h"
  377. X
  378. #ifdef  __STDC__
  379. #include "malloc.h"
  380. #else
  381. extern   char * malloc();
  382. #endif
  383. X
  384. #ifndef   __STDC__
  385. #define   time_t    long
  386. #define   size_t   int
  387. #endif
  388. X
  389. #define OM_TITLES       7
  390. #define SP_TITLES       9
  391. #define AP_TITLES       6
  392. #define SYS_TITLES      4
  393. X
  394. extern   struct as_focus * pr_getfd();
  395. X
  396. struct uiwindow *set_window;
  397. int      sp_x1, sp_y1, sp_x2, sp_y2;
  398. int      sp_ready;
  399. X
  400. static int spmem;
  401. X
  402. static char *om_titles[ OM_TITLES ];
  403. static char *sp_titles[ SP_TITLES ];
  404. static char *ap_titles[ AP_TITLES ];
  405. static char *sys_titles[ SYS_TITLES ];
  406. static char t_buffer[ BW_EBUFSIZE ];
  407. static char set_buffer[ 64 ];
  408. static struct sfs_orbit *ap_oldorbit = NULL;
  409. X
  410. extern int null_poll();
  411. X
  412. sfs_om( sorbit_array, n_orbits )
  413. X   struct sfs_orbit **sorbit_array;
  414. X   int n_orbits;
  415. X   {
  416. X   int orbit, keep_on, item, c;
  417. X   long l;
  418. X   static int x_elements = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT;
  419. X
  420. X   ui_fbox( main_window->u_x1, main_window->u_y1,
  421. X      main_window->u_x2, main_window->u_y2, BLACK, SOLID );
  422. X
  423. X   if ( sp_ready == 0 )
  424. X      {
  425. X      sp_init();
  426. X      sp_ready = 1;
  427. X      }
  428. X
  429. X   tl_window( OM_TITLE );
  430. X   tr_window( SOP_TITLE );
  431. X   bl_window( SFSM_PEBL );
  432. X   br_window( AP_TITLE );
  433. X   w1.is_drawn = FALSE;
  434. X   w2.is_drawn = FALSE;
  435. X   ap_oldorbit = NULL;
  436. X   sfsm_sp( FALSE, sorbit_array, sfs_curorbit, n_orbits );
  437. X
  438. X   keep_on = TRUE;
  439. X   while ( keep_on == TRUE )
  440. X      {
  441. X
  442. #ifdef  BLOCKEDOUT
  443. X      pe_calc( sorbit_array, n_orbits );
  444. X      pe_draw( w3.window, sorbit_array[ sfs_curorbit ]->aorbit->focus,
  445. X     sorbit_array, n_orbits, NULL, NULL, (long) 0, x_elements );
  446. #endif
  447. X
  448. X      bw_message( MES_OM );
  449. X
  450. X      pr_stripcr( sfs_prname );
  451. X      sprintf( om_titles[ 0 ], OM_SPT, sfs_prname );
  452. X      sprintf( om_titles[ 1 ], OM_SON, sfs_curorbit + 1 );
  453. X      strcpy( om_titles[ 2 ],  OM_SOP );
  454. X      sprintf( om_titles[ 3 ], OM_SIP, sfs_insertion );
  455. X      strcpy( om_titles[ 4 ],  OM_SSP );
  456. X      strcpy( om_titles[ 5 ],  OM_VCO );
  457. X      strcpy( om_titles[ 6 ],  OM_EXIT );
  458. X
  459. X      item = ui_list( MENU_TITLED, w1.window->x1, w1.window->y1,
  460. X     w1.window->x2, w1.window->y2,
  461. X     OM_TTL,
  462. X     OM_TITLES, om_titles, cl_mfore, cl_mback,
  463. X     cl_marker, &w1 );
  464. X
  465. X      switch( item )
  466. X         {
  467. X     case 0:
  468. X        get_string( SPT_TITLE, SPT_LEGEND, SPT_PROMPT,
  469. X           sfs_prname );
  470. X        sprintf( om_titles[ 0 ], OM_SPT, sfs_prname );
  471. X        w1.is_drawn = FALSE;
  472. X            break;
  473. X     case 1:
  474. X        sprintf( sfs_tbuf, SON_LEGEND, ORBITS );
  475. X        sfs_curorbit = get_int( SON_TITLE,
  476. X           sfs_tbuf, SON_PROMPT,
  477. X           sfs_curorbit, 1, ORBITS ) - 1;
  478. X        if ( sorbit_array[ sfs_curorbit ] == NULL )
  479. X               {
  480. X           pr_default( sorbit_array, sfs_curorbit, n_orbits, DEFAULTFD );
  481. X               }
  482. X        sprintf( om_titles[ 1 ],
  483. X           OM_SON, sfs_curorbit + 1 );
  484. X            sfsm_sp( FALSE, sorbit_array, sfs_curorbit, n_orbits );
  485. X        w1.is_drawn = FALSE;
  486. X        w2.is_drawn = FALSE;
  487. X        break;
  488. X     case 2:
  489. X        w2.is_drawn = FALSE;
  490. X        sfsm_sp( TRUE, sorbit_array, sfs_curorbit, n_orbits );
  491. X            break;
  492. X     case 3:
  493. X        sfs_insertion = get_long( SIP_TITLE,
  494. X           SIP_LEGEND, SIP_PROMPT,
  495. X               (long) sfs_insertion, 
  496. X           (long) 0,
  497. X           (long) sorbit_array[ sfs_curorbit ]->aorbit->period );
  498. X        sprintf( om_titles[ 3 ],
  499. X           OM_SIP, sfs_insertion );
  500. X        w1.is_drawn = FALSE;
  501. X        break;
  502. X     case 4:
  503. X        w2.is_drawn = FALSE;
  504. X            sfs_sysp();
  505. X            break;
  506. X     case 5:
  507. X        pe_calc( sorbit_array, n_orbits, null_poll );
  508. X        pe_draw( w3.window, sorbit_array[ sfs_curorbit ]->aorbit->focus,
  509. X           sorbit_array, n_orbits, NULL, NULL, (long) 0, x_elements );
  510. X            break;
  511. X     case TK_EXIT:
  512. X     case 6:
  513. X        keep_on = FALSE;
  514. X        c = get_yn( OM_SF );
  515. X        if ( c == TRUE )
  516. X               {
  517. X           get_string( SF_TITLE,
  518. X          SF_LEGEND,
  519. X          SF_PROMPT,
  520. X                  sfs_program );
  521. X           pr_save( sfs_program, sorbit_array, n_orbits, sfs_prname );
  522. X               }
  523. X        w1.is_drawn = FALSE;
  524. X        break;
  525. X         }
  526. X      }
  527. X   }
  528. X
  529. sp_init()
  530. X   {
  531. X   int height, length, midx, midy, c;
  532. X
  533. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  534. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  535. X
  536. X   length = ( main_window->u_x2 * 3 ) / 5;
  537. X   sp_x1  = midx - length / 2;
  538. X   sp_x2  = midx + length / 2;
  539. X   height = main_window->u_y2 / 2;
  540. X   sp_y1  = midy - height / 2;
  541. X   sp_y2  = midy + height / 2;
  542. X
  543. X   for ( c = 0; c < OM_TITLES; ++c )
  544. X      {
  545. X      if ( ( om_titles[ c ] = malloc( 64 ) ) == NULL )
  546. X         {
  547. X     bw_error( MM_MEMERR );
  548. X         }
  549. X      }
  550. X   for ( c = 0; c < SP_TITLES; ++c )
  551. X      {
  552. X      if ( ( sp_titles[ c ] = malloc( 64 ) ) == NULL)
  553. X         {
  554. X     bw_error( OPM_MEMERR );
  555. X         }
  556. X      }
  557. X   for ( c = 0; c < AP_TITLES; ++c )
  558. X      {
  559. X      if ( ( ap_titles[ c ] = malloc( 64 ) ) == NULL)
  560. X         {
  561. X     bw_error( APM_MEMERR );
  562. X         }
  563. X      }
  564. X   for ( c = 0; c < SYS_TITLES; ++c )
  565. X      {
  566. X      if ( ( sys_titles[ c ] = malloc( 64 ) ) == NULL)
  567. X         {
  568. X     bw_error( SPM_MEMERR );
  569. X         }
  570. X      }
  571. X
  572. X   }
  573. X
  574. sfs_sysp()
  575. X   {
  576. X   int c, y, item;
  577. X
  578. X   /* set up titles for menu */
  579. X
  580. X   sprintf( sys_titles[ 0 ], SSP_TF,
  581. X      (long) sfs_tfactor );
  582. X   sprintf( sys_titles[ 1 ], SSP_UI,
  583. X      (long) sfs_inc );
  584. X   sprintf( sys_titles[ 2 ], SSP_TPL,
  585. X      vpt_level );
  586. X   sprintf( sys_titles[ 3 ], SSP_EXIT );
  587. X   w2.is_drawn = FALSE;
  588. X
  589. X   bw_message( MES_SSP );
  590. X
  591. X   y = TRUE;
  592. X   while( y == TRUE )
  593. X      {
  594. X
  595. X      item = ui_list( MENU_TITLED, w2.window->x1, w2.window->y1,
  596. X     w2.window->x2, w2.window->y2,
  597. X     SSP_TITLE,
  598. X     SYS_TITLES, sys_titles,
  599. X     cl_mfore, cl_mback,
  600. X     cl_marker, &w2 );
  601. X
  602. X      /* Process the argument */
  603. X
  604. X      switch( item )
  605. X         {
  606. X         case 0:
  607. X        sfs_tfactor = get_long( TF_TITLE,
  608. X           TF_LEGEND,
  609. X           TF_PROMPT,
  610. X               (long) sfs_tfactor,
  611. X               (long) 1, (long) 0 );
  612. X        sprintf( sys_titles[ 0 ], SSP_TF,
  613. X           (long) sfs_tfactor );
  614. X        w2.is_drawn = FALSE;
  615. X            break;
  616. X         case 1:
  617. X        sfs_inc = get_long( UI_TITLE,
  618. X           UI_LEGEND,
  619. X           UI_PROMPT,
  620. X           (long) sfs_inc,
  621. X           (long) 1, (long) 0 );
  622. X        sprintf( sys_titles[ 1 ], SSP_UI,
  623. X           (long) sfs_inc );
  624. X        w2.is_drawn = FALSE;
  625. X            break;
  626. X         case 2:
  627. X        vpt_level = get_int( TPL_TITLE,
  628. X           TPL_LEGEND,
  629. X           TPL_PROMPT,
  630. X               vpt_level, 1, 2 );
  631. X        sprintf( sys_titles[ 2 ], SSP_TPL,
  632. X           vpt_level );
  633. X        w2.is_drawn = FALSE;
  634. X            break;
  635. X     case TK_EXIT:
  636. X         case 3:
  637. X        y = FALSE;
  638. X            break;
  639. X         }
  640. X
  641. X      }
  642. X   }
  643. X
  644. /***************************************************************
  645. X
  646. X   sfsm_sp()    set orbital parameters
  647. X
  648. ***************************************************************/
  649. X
  650. sfsm_sp( execute, sorbit_array, orbit_n, n_orbits )
  651. X   int execute;
  652. X   struct sfs_orbit **sorbit_array;
  653. X   int orbit_n, n_orbits;
  654. X   {
  655. X   register int c;
  656. X   int item, y;
  657. X   static char x_buffer[ BW_EBUFSIZE ];
  658. X   static struct menu_box fs_box;
  659. X
  660. X   if ( execute == TRUE )
  661. X      {
  662. X      bw_message( MES_SP );
  663. X      }
  664. X
  665. X   y = TRUE;
  666. X   while( y == TRUE )
  667. X      {
  668. X
  669. X      if ( sorbit_array[ orbit_n ] != ap_oldorbit )
  670. X     {
  671. X     or_init( sorbit_array[ sfs_curorbit ]->aorbit,
  672. X        sorbit_array[ sfs_curorbit ]->aorbit->periapsis,
  673. X        sorbit_array[ sfs_curorbit ]->aorbit->apoapsis );
  674. X
  675. X     sfs_ap( sorbit_array, sfs_curorbit );
  676. X     ap_oldorbit = sorbit_array[ orbit_n ];
  677. X
  678. X     /* set up titles for menu */
  679. X
  680. X     sprintf( sp_titles[ 0 ], SOP_SOF,
  681. X        sorbit_array[ sfs_curorbit ]->aorbit->focus->fdfile );
  682. X     sprintf( sp_titles[ 1 ], SOP_SN,
  683. X        sorbit_array[ sfs_curorbit ]->name );
  684. X     sprintf( sp_titles[ 2 ], SOP_SDF,
  685. X        sorbit_array[ sfs_curorbit ]->surfile );
  686. X     sprintf( sp_titles[ 3 ], SOP_PRI,
  687. X        sorbit_array[ sfs_curorbit ]->aorbit->periapsis );
  688. X     sprintf( sp_titles[ 4 ], SOP_APO,
  689. X        sorbit_array[ sfs_curorbit ]->aorbit->apoapsis );
  690. X     sprintf( sp_titles[ 5 ], SOP_INC,
  691. X        sorbit_array[ sfs_curorbit ]->aorbit->inclination );
  692. X     sprintf( sp_titles[ 6 ], SOP_ARP,
  693. X        sorbit_array[ sfs_curorbit ]->aorbit->arg_per );
  694. X     sprintf( sp_titles[ 7 ], SOP_LAN,
  695. X        sorbit_array[ sfs_curorbit ]->aorbit->lon_an );
  696. X     strcpy( sp_titles[ 8 ], SOP_EXIT );
  697. X
  698. X     tr_window( x_buffer );
  699. X     w2.is_drawn = FALSE;
  700. X     }
  701. X
  702. X      sprintf( x_buffer, SOP_TITLE2, sfs_curorbit + 1 );
  703. X
  704. X      if ( execute == FALSE )
  705. X     {
  706. X     uil_draw( MENU_TITLED, w2.window->x1, w2.window->y1,
  707. X        w2.window->x2, w2.window->y2,
  708. X        x_buffer, SP_TITLES, sp_titles,
  709. X        cl_mfore, cl_mback, cl_marker, &w2 );
  710. X
  711. X     return TRUE;
  712. X     }
  713. X
  714. X      item = ui_list( MENU_TITLED, w2.window->x1, w2.window->y1,
  715. X     w2.window->x2, w2.window->y2,
  716. X     x_buffer, SP_TITLES, sp_titles,
  717. X     cl_mfore, cl_mback, cl_marker, &w2 );
  718. X
  719. X      /* Process the argument */
  720. X
  721. X      switch( item )
  722. X     {
  723. X     case 0:
  724. X        sfsm_getspw();
  725. X        fs_box.is_drawn = FALSE;
  726. X        item = ui_ftext( sp_x1, sp_y1, sp_x2, sp_y2, "*.fd",
  727. X           SOF_TITLE,
  728. X           &fs_box, d_titles, d_entries, MAX_ENTRIES,
  729. X           cl_mback, cl_mfore, cl_marker );
  730. X        fntolc( d_titles[ item ] );
  731. X
  732. X        sorbit_array[ sfs_curorbit ]->aorbit->focus
  733. X           = pr_getfd( sorbit_array, sfs_curorbit, n_orbits,
  734. X           d_titles[ item ]  );
  735. X        sprintf( sp_titles[ 0 ], SOP_SOF,
  736. X           sorbit_array[ sfs_curorbit ]->aorbit->focus->fdfile );
  737. X        sfsm_putspw();
  738. X        w2.is_drawn = FALSE;
  739. X        break;
  740. X
  741. X     case 1:
  742. X        sprintf( t_buffer, SN_TITLE, sfs_curorbit + 1);
  743. X        get_string( set_buffer, SN_LEGEND,
  744. X           SN_PROMPT, sfs_tbuf );
  745. X        strcpy( sorbit_array[ sfs_curorbit ]->name, sfs_tbuf );
  746. X        sprintf( sp_titles[ 1 ], SOP_SN,
  747. X           sorbit_array[ sfs_curorbit ]->name );
  748. X        w2.is_drawn = FALSE;
  749. X            break;
  750. X
  751. X     case 2:
  752. X        sfsm_getspw();
  753. X        fs_box.is_drawn = FALSE;
  754. X        item = ui_ftext( sp_x1, sp_y1, sp_x2, sp_y2, "*.spd",
  755. X           SDF_TITLE,
  756. X           &fs_box, d_titles, d_entries, MAX_ENTRIES,
  757. X           cl_mback, cl_mfore, cl_marker );
  758. X        fntolc( d_titles[ item ] );
  759. X        strncpy( sorbit_array[ sfs_curorbit ]->surfile,
  760. X           d_titles[ item ], SFS_FILESIZE - 2 );
  761. X        sprintf( sp_titles[ 2 ], SOP_SDF,
  762. X           sorbit_array[ sfs_curorbit ]->surfile );
  763. X        sfsm_putspw();
  764. X        w2.is_drawn = FALSE;
  765. X        break;
  766. X
  767. X     case 3:
  768. X        sprintf( t_buffer, PRI_TITLE, sfs_curorbit + 1 );
  769. X        sprintf( sfs_tbuf, PRI_LEGEND,
  770. X           (double) sorbit_array[ sfs_curorbit ]->aorbit->apoapsis );
  771. X        sorbit_array[ sfs_curorbit ]->aorbit->periapsis = get_double( t_buffer,
  772. X           sfs_tbuf,
  773. X           PRI_PROMPT,
  774. X           (double) sorbit_array[ sfs_curorbit ]->aorbit->periapsis,
  775. X           (double) 0.0,
  776. X           (double) sorbit_array[ sfs_curorbit ]->aorbit->apoapsis );
  777. X        sfsm_clpe();
  778. X        sprintf( sp_titles[ 3 ], SOP_PRI,
  779. X           sorbit_array[ sfs_curorbit ]->aorbit->periapsis );
  780. X        w2.is_drawn = FALSE;
  781. X            break;
  782. X
  783. X     case 4:
  784. X        sprintf( t_buffer, APO_TITLE, sfs_curorbit + 1 );
  785. X        sprintf( sfs_tbuf, APO_LEGEND,
  786. X           (double) sorbit_array[ sfs_curorbit ]->aorbit->periapsis );
  787. X        sorbit_array[ sfs_curorbit ]->aorbit->apoapsis = get_double( t_buffer,
  788. X           sfs_tbuf,
  789. X           APO_PROMPT,
  790. X           (double) sorbit_array[ sfs_curorbit ]->aorbit->apoapsis,
  791. X           (double) sorbit_array[ sfs_curorbit ]->aorbit->periapsis,
  792. X           (double) 0.0 );
  793. X        sfsm_clpe();
  794. X        sprintf( sp_titles[ 4 ], SOP_APO,
  795. X           sorbit_array[ sfs_curorbit ]->aorbit->apoapsis );
  796. X        w2.is_drawn = FALSE;
  797. X            break;
  798. X     case 5:
  799. X        sprintf( t_buffer, INC_TITLE, sfs_curorbit + 1);
  800. X        sprintf( sfs_tbuf, INC_LEGEND,
  801. X           (double) OR_INC_MIN, (double) OR_INC_MAX );
  802. X        sorbit_array[ sfs_curorbit ]->aorbit->inclination = get_double( t_buffer,
  803. X           sfs_tbuf,
  804. X           INC_PROMPT,
  805. X           sorbit_array[ sfs_curorbit ]->aorbit->inclination,
  806. X           (double) OR_INC_MIN, (double) OR_INC_MAX );
  807. X        sfsm_clpe();
  808. X
  809. X            /*** inclination cannot be 90 or -90 ***/
  810. X
  811. X            if ( sorbit_array[ sfs_curorbit ]->aorbit->inclination == 90.0 )
  812. X               {
  813. X               sorbit_array[ sfs_curorbit ]->aorbit->inclination = 89.9999;
  814. X               }
  815. X            if ( sorbit_array[ sfs_curorbit ]->aorbit->inclination == -90.0 )
  816. X               {
  817. X               sorbit_array[ sfs_curorbit ]->aorbit->inclination = -89.9999;
  818. X               }
  819. X
  820. X        sprintf( sp_titles[ 5 ], SOP_INC,
  821. X           sorbit_array[ sfs_curorbit ]->aorbit->inclination );
  822. X        w2.is_drawn = FALSE;
  823. X            break;
  824. X     case 6:
  825. X        sprintf( t_buffer, ARP_TITLE, sfs_curorbit + 1 );
  826. X        sprintf( sfs_tbuf, ARP_LEGEND,
  827. X           (double) OR_ARP_MIN, (double) OR_ARP_MAX );
  828. X        sorbit_array[ sfs_curorbit ]->aorbit->arg_per = get_double( t_buffer,
  829. X           sfs_tbuf,
  830. X           ARP_PROMPT,
  831. X           sorbit_array[ sfs_curorbit ]->aorbit->arg_per,
  832. X           (double) OR_ARP_MIN, (double) OR_ARP_MAX );
  833. X        sfsm_clpe();
  834. X        sprintf( sp_titles[ 6 ], SOP_ARP,
  835. X           sorbit_array[ sfs_curorbit ]->aorbit->arg_per );
  836. X        w2.is_drawn = FALSE;
  837. X            break;
  838. X     case 7:
  839. X        sprintf( t_buffer, LAN_TITLE, sfs_curorbit +1 );
  840. X        sprintf( sfs_tbuf, LAN_LEGEND,
  841. X           OR_LAN_MIN, OR_LAN_MAX );
  842. X        sorbit_array[ sfs_curorbit ]->aorbit->lon_an = get_double( t_buffer,
  843. X           sfs_tbuf,
  844. X           LAN_PROMPT,
  845. X           sorbit_array[ sfs_curorbit ]->aorbit->lon_an,
  846. X           (double) OR_LAN_MIN, (double) OR_LAN_MAX );
  847. X        sfsm_clpe();
  848. X        sprintf( sp_titles[ 7 ], SOP_LAN,
  849. X           sorbit_array[ sfs_curorbit ]->aorbit->lon_an );
  850. X        w2.is_drawn = FALSE;
  851. X            break;
  852. X     case TK_EXIT:
  853. X     case 8:
  854. X            y = 0;
  855. X            break;
  856. X         }
  857. X
  858. X      if ( w2.is_drawn == FALSE )
  859. X     {
  860. X     or_init( sorbit_array[ sfs_curorbit ]->aorbit,
  861. X        sorbit_array[ sfs_curorbit ]->aorbit->periapsis,
  862. X        sorbit_array[ sfs_curorbit ]->aorbit->apoapsis );
  863. X     sfs_ap( sorbit_array, sfs_curorbit );
  864. X     }
  865. X      }
  866. X   }
  867. X
  868. sfs_ap( sorbit_array, orbit_n )
  869. X   struct sfs_orbit **sorbit_array;
  870. X   int orbit_n;
  871. X   {
  872. X   static char x_buffer[ BW_EBUFSIZE ];
  873. X
  874. X   /* set up titles for menu */
  875. X
  876. X   sprintf( ap_titles[ 0 ], AP_MAS,
  877. X      sorbit_array[ orbit_n ]->aorbit->focus->mass );
  878. X   sprintf( ap_titles[ 1 ], AP_RAD,
  879. X      sorbit_array[ orbit_n ]->aorbit->focus->radius );
  880. X   sprintf( ap_titles[ 2 ], AP_SID,
  881. X      sorbit_array[ orbit_n ]->aorbit->focus->sid_day  );
  882. X   sprintf( ap_titles[ 3 ], AP_SMI,
  883. X      sorbit_array[ sfs_curorbit ]->aorbit->semiminor );
  884. X   sprintf( ap_titles[ 4 ], AP_ECC,
  885. X      sorbit_array[ sfs_curorbit ]->aorbit->eccentricity );
  886. X   sprintf( ap_titles[ 5 ], AP_PER,
  887. X      sorbit_array[ sfs_curorbit ]->aorbit->period,
  888. X      sorbit_array[ sfs_curorbit ]->aorbit->period / (double) 86400 );
  889. X
  890. X   sprintf( x_buffer, AP_TITLE2, orbit_n + 1 );
  891. X
  892. X   br_window( t_buffer );
  893. X   w4.is_drawn = FALSE;
  894. X   uil_draw( MENU_TITLED, w4.window->x1, w4.window->y1,
  895. X      w4.window->x2, w4.window->y2, 
  896. X      x_buffer, AP_TITLES, ap_titles,
  897. X      cl_mfore, cl_mback, cl_marker, &w4 );
  898. X
  899. X
  900. X   }
  901. X
  902. get_yn( text )
  903. X   char *text;
  904. X   {
  905. X   register int c;
  906. X   static struct uiwindow *yn_window;
  907. X
  908. X   sfsm_getspw();
  909. X
  910. X   c = ui_yn( sp_x1, sp_y1, sp_x2, sp_y2,
  911. X      cl_mback, cl_mfore, cl_marker, TRUE,
  912. X      text, GETYN_NO, GETYN_YES, &yn_window );
  913. X
  914. X   sfsm_putspw();
  915. X   return c;
  916. X   }
  917. X
  918. get_string( title, text, prompt, buffer )
  919. X   char *title, *text, *prompt, *buffer;
  920. X   {
  921. X   sfsm_getspw();
  922. X
  923. X   get_window();
  924. X   ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore, cl_marker,
  925. X      1, title,
  926. X      text, prompt, set_buffer, &set_window );
  927. X   if ( set_buffer[ 0 ] != 0 )
  928. X      {
  929. X      strcpy( buffer, set_buffer );
  930. X      }
  931. X
  932. X   sfsm_putspw();
  933. X   }
  934. X
  935. get_int( title, text, prompt, oldvalue, minimum, maximum )
  936. X   char *title, *text, *prompt;
  937. X   int oldvalue, minimum, maximum;
  938. X   {
  939. X   char *_text;
  940. X   int y;
  941. X   static int n;
  942. X
  943. X   sfsm_getspw();
  944. X
  945. X   _text = text;
  946. X   y = 1;
  947. X   while( y == 1 )
  948. X      {
  949. X      get_window();
  950. X      ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore,
  951. X         cl_marker, 1, title,
  952. X         _text, prompt, set_buffer, &set_window );
  953. X      if ( set_buffer[ 0 ] == 0 )
  954. X     {
  955. X     sfsm_putspw();
  956. X         return oldvalue;
  957. X         }
  958. X
  959. X      sscanf( set_buffer, "%d",  &n );
  960. X      y = 0;
  961. X      if ( n < minimum )
  962. X         {
  963. X     sprintf( sfs_tbuf, "%s %ld; %s.", MINERR, minimum - 1, PTA );
  964. X         _text = sfs_tbuf;
  965. X         y = 1;
  966. X         }
  967. X      if ( ( maximum != 0 ) && ( n > maximum ))
  968. X         {
  969. X         y = 1;
  970. X     sprintf( sfs_tbuf, "%s %ld; %s.", MAXERR, maximum + 1, PTA );
  971. X         _text = sfs_tbuf;
  972. X         }
  973. X      }
  974. X
  975. X   sfsm_putspw();
  976. X   return n;
  977. X   }
  978. X
  979. long
  980. get_long( title, text, prompt, oldvalue, minimum, maximum )
  981. X   char *title, *text, *prompt;
  982. X   long oldvalue, minimum, maximum;
  983. X   {
  984. X   char *_text;
  985. X   int y;
  986. X   static long n;
  987. X
  988. X   sfsm_getspw();                       /* save the set param window */
  989. X
  990. X   _text = text;
  991. X   y = TRUE;
  992. X   while( y == TRUE )
  993. X      {
  994. X      get_window();
  995. X      ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore,
  996. X         cl_marker, 1, title,
  997. X         _text, prompt, set_buffer, &set_window );
  998. X
  999. X      if ( set_buffer[ 0 ] == 0 )
  1000. X     {
  1001. X     sfsm_putspw();
  1002. X         return oldvalue;
  1003. X         }
  1004. X
  1005. X      sscanf( set_buffer, "%ld",  &n );
  1006. X      y = 0;
  1007. X      if ( n < minimum )
  1008. X         {
  1009. X     sprintf( sfs_tbuf, "%s %ld; %s.", MINERR, minimum - 1, PTA );
  1010. X         _text = sfs_tbuf;
  1011. X         y = 1;
  1012. X         }
  1013. X      if ( ( maximum != 0 ) && ( n > maximum ))
  1014. X         {
  1015. X         y = 1;
  1016. X     sprintf( sfs_tbuf, "%s %ld; %s.", MAXERR, maximum + 1, PTA );
  1017. X         _text = sfs_tbuf;
  1018. X         }
  1019. X      }
  1020. X
  1021. X   sfsm_putspw();
  1022. X   return n;
  1023. X   }
  1024. X
  1025. double
  1026. get_double( title, text, prompt, oldvalue, minimum, maximum )
  1027. X   char *title, *text, *prompt;
  1028. X   double oldvalue, minimum, maximum;
  1029. X   {
  1030. X   char *_text;
  1031. X   int y;
  1032. X   static double n;
  1033. X
  1034. X   sfsm_getspw();
  1035. X
  1036. X   _text = text;
  1037. X   y = 1;
  1038. X   while( y == 1 )
  1039. X      {
  1040. X      get_window();
  1041. X      ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore,
  1042. X         cl_marker, 1, title,
  1043. X         _text, prompt, set_buffer, &set_window );
  1044. X
  1045. X      if ( set_buffer[ 0 ] == 0 )
  1046. X     {
  1047. X     sfsm_putspw();
  1048. X         return oldvalue;
  1049. X         }
  1050. X
  1051. X      sscanf( set_buffer, "%lf",  &n );
  1052. X      y = 0;
  1053. X      if ( n < minimum )
  1054. X         {
  1055. X     sprintf( sfs_tbuf, "%s %.2lf; %s.", MINERR, minimum - 1, PTA );
  1056. X         _text = sfs_tbuf;
  1057. X         y = 1;
  1058. X         }
  1059. X      if ( ( maximum != 0.0 ) && ( n > maximum ))
  1060. X         {
  1061. X         y = 1;
  1062. X     sprintf( sfs_tbuf, "%s %.2lf; %s.", MAXERR, maximum + 1, PTA );
  1063. X         _text = sfs_tbuf;
  1064. X         }
  1065. X      }
  1066. X
  1067. X   sfsm_putspw();
  1068. X   return n;
  1069. X   }
  1070. X
  1071. /***************************************************************
  1072. X
  1073. X   get_window()         This function is called prior to ui_dial
  1074. X            in get_xxx() functions in order to set
  1075. X            the title bar background color to cl_marker.
  1076. X            Since ui_dial does not allow specification
  1077. X            of a title bar color, this will set it, and
  1078. X            once set it will remian the same.
  1079. X
  1080. ***************************************************************/
  1081. X
  1082. get_window()
  1083. X   {
  1084. X   if ( set_window == NULL )
  1085. X      {
  1086. X      set_window = ui_window( sp_x1, sp_y1, sp_x2, sp_y2, TRUE, cl_marker,
  1087. X     BLACK, "", TRUE, cl_mfore, TRUE, BLACK, cl_mback, SOLID, FALSE );
  1088. X      }
  1089. X   }
  1090. X
  1091. sfsm_clpe()
  1092. X   {
  1093. X   if ( w3.window == NULL )
  1094. X      {
  1095. X      return BW_ERROR;
  1096. X      }
  1097. X   ui_fbox( w3.window->u_x1, w3.window->u_y1,
  1098. X      w3.window->u_x2, w3.window->u_y2, BLACK, SOLID );
  1099. X   ui_fbox( w3.window->u_x1, w3.window->u_y1,
  1100. X      w3.window->u_x2, w3.window->u_y2, /* cl_mback */ WHITE, GRID );
  1101. X   ui_rewindow( w3.window, SFSM_PEBL );
  1102. X
  1103. X   }
  1104. X
  1105. sfsm_getspw()
  1106. X   {
  1107. X   size_t x_size;
  1108. X
  1109. X   gr_imsave( GR_PRIMARY, TRUE, sp_x1, sp_y1, sp_x2, sp_y2, &spmem );
  1110. X   }
  1111. X
  1112. sfsm_putspw()
  1113. X   {
  1114. X   gr_imsave( GR_PRIMARY, FALSE, sp_x1, sp_y1, sp_x2, sp_y2, &spmem );
  1115. X   gr_imfree( spmem );
  1116. X   }
  1117. X
  1118. null_poll()
  1119. X   {
  1120. X   }
  1121. SHAR_EOF
  1122. chmod 0644 sfs/sfs/sfsm_om.c ||
  1123. echo 'restore of sfs/sfs/sfsm_om.c failed'
  1124. Wc_c="`wc -c < 'sfs/sfs/sfsm_om.c'`"
  1125. test 20737 -eq "$Wc_c" ||
  1126.     echo 'sfs/sfs/sfsm_om.c: original size 20737, current size' "$Wc_c"
  1127. rm -f _shar_wnt_.tmp
  1128. fi
  1129. # ============= sfs/sfs/sfsx.c ==============
  1130. if test -f 'sfs/sfs/sfsx.c' -a X"$1" != X"-c"; then
  1131.     echo 'x - skipping sfs/sfs/sfsx.c (File already exists)'
  1132.     rm -f _shar_wnt_.tmp
  1133. else
  1134. > _shar_wnt_.tmp
  1135. echo 'x - extracting sfs/sfs/sfsx.c (Text)'
  1136. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsx.c' &&
  1137. /***************************************************************
  1138. X
  1139. X    sfsx.c        Space Flight Simulator
  1140. X            Orbital Simulation Module -- Main Segment
  1141. X
  1142. X            Copyright (c) 1991, Ted A. Campbell
  1143. X
  1144. X            Bywater Software
  1145. X            P. O. Box 4023 
  1146. X            Duke Station 
  1147. X            Durham, NC  27706
  1148. X
  1149. X            email: tcamp@hercules.acpub.duke.edu
  1150. X
  1151. X    Copyright and Permissions Information:
  1152. X
  1153. X    All U.S. and international copyrights are claimed by the
  1154. X    author. The author grants permission to use this code
  1155. X    and software based on it under the following conditions:
  1156. X    (a) in general, the code and software based upon it may be 
  1157. X    used by individuals and by non-profit organizations; (b) it
  1158. X    may also be utilized by governmental agencies in any country,
  1159. X    with the exception of military agencies; (c) the code and/or
  1160. X    software based upon it may not be sold for a profit without
  1161. X    an explicit and specific permission from the author, except
  1162. X    that a minimal fee may be charged for media on which it is
  1163. X    copied, and for copying and handling; (d) the code must be 
  1164. X    distributed in the form in which it has been released by the
  1165. X    author; and (e) the code and software based upon it may not 
  1166. X    be used for illegal activities. 
  1167. X
  1168. ***************************************************************/
  1169. X
  1170. /***  Include Files */
  1171. X
  1172. #include "stdio.h"
  1173. #include "signal.h"
  1174. #include "time.h"
  1175. #include "math.h"
  1176. #include "sfsx.h"
  1177. X
  1178. #ifdef  __STDC__
  1179. #include "malloc.h"
  1180. #include "process.h"
  1181. #else
  1182. extern  char * malloc();
  1183. #define size_t   int
  1184. #define time_t   long
  1185. #endif
  1186. X
  1187. /***  Local Data */
  1188. X
  1189. int     fo_xcenter, fo_ycenter;
  1190. X
  1191. static  char *em_titles[ EM_TITLES ];
  1192. static  FILE *data;
  1193. static int x_zoom = FALSE;   /* boolean: use zoom display? */
  1194. static int d_zoom;           /* zoom window display */
  1195. static int d_upper;          /* upper window display */
  1196. static int d_lower;          /* lower window display */
  1197. struct uiwindow *e_wind;     /* window for elements */
  1198. static x_init = FALSE;       /* is video system initialized? */
  1199. static int *x_elements;      /* pointer to elements to toggle */
  1200. static struct sfs_display **x_displays;
  1201. static int n_displays = 0;   /* number of displays */
  1202. static char **t_array;       /* title array */
  1203. static char pr_file[ SFS_FILESIZE ];
  1204. X
  1205. extern int sfsx_sigint();
  1206. extern int *sfsx_curel();
  1207. extern int sfsx_poll();
  1208. X
  1209. /****************************************************************
  1210. X
  1211. X    main()          Main Program Function
  1212. X
  1213. ****************************************************************/
  1214. X
  1215. main( argc, argv )
  1216. X   int argc;
  1217. X   char **argv;
  1218. X   {
  1219. X   int x_resume;                /* resume execution? */
  1220. X
  1221. X   /***    First some precautionary measures               */
  1222. X   /***    Load "chain" so that the loader (sfs) will exit */
  1223. X   /***    in the case of any unexpected exit              */
  1224. X
  1225. X   if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != NULL )
  1226. X      {
  1227. X      fprintf( data, "%s \n", SFSCH_EXIT );
  1228. X      fclose( data );
  1229. X      }
  1230. X
  1231. X   /***    Now set a signal handler so that a SIGINT       */
  1232. X   /***    (control-C under DOS, DEL under Unix) will      */
  1233. X   /***    exit gracefully                                 */
  1234. X
  1235. X   signal( SIGINT, sfsx_sigint );
  1236. X
  1237. X   /***    Set up initial program file */
  1238. X
  1239. X   if ( argc > 1 )
  1240. X      {
  1241. X      strcpy( pr_file, argv[ 1 ] );
  1242. X      }
  1243. X   else
  1244. X      {
  1245. X      strcpy( pr_file, SFS_DEFAULTPROG );
  1246. X      }
  1247. X
  1248. X   /***  Initialize Bywater user interface */
  1249. X
  1250. X   ui_init();
  1251. X   /* Return if initialization failed */
  1252. X
  1253. X   if ( ui_grwind->initialized == FALSE )
  1254. X      {
  1255. X      fprintf( stderr, "Graphics system is not initialized.\n" );
  1256. X      return -1;
  1257. X      }
  1258. X
  1259. #ifdef  OLD_DEBUG
  1260. X   fprintf( stderr, "ui is now initialized\n" );
  1261. #endif
  1262. X
  1263. X   /***  Initialize colors */
  1264. X
  1265. X   sfsx_colors();
  1266. X
  1267. X   /* reset icon colors */
  1268. X
  1269. X   if ( gr_colors > 2 )
  1270. X      {
  1271. X      ui_seticons( cl_mback, cl_marker );
  1272. X      }
  1273. X
  1274. X   /***  Initialize parameters */
  1275. X
  1276. X   vpt_init();
  1277. X   vpt_level = 1;
  1278. X   sfsx_font( 0 );
  1279. X
  1280. X   /***  Set up the screen */
  1281. X
  1282. X   sfsx_screen();
  1283. X
  1284. X   fo_xcenter = fo_window->x1 + (( fo_window->x2 - fo_window->x1 ) / 2 );
  1285. X   fo_ycenter = fo_window->y1 + (( fo_window->y2 - fo_window->y1 ) / 2 );
  1286. X
  1287. #ifdef  OLD_DEBUG
  1288. X   fprintf( stderr, "screen is now drawn\n" );
  1289. #endif
  1290. X
  1291. X   /***  Initialize error handler */
  1292. X
  1293. X   err_init();
  1294. X
  1295. #ifdef  OLD_DEBUG
  1296. X   fprintf( stderr, "error handler is now initialized\n" );
  1297. #endif
  1298. X
  1299. X   sfsx( pr_file );
  1300. X
  1301. X   }
  1302. X
  1303. sfsx( program )
  1304. X   char *program;
  1305. X   {
  1306. X   register int orbit;          /* cycle through orbits */
  1307. X   register int c;              /* a multipurpose counter */
  1308. X   int x_continue;              /* continue main loop */
  1309. X   long x_target;               /* target time (met) for next display update */
  1310. X   long x_next;                 /* next target time (to calculate rotation) */
  1311. X   static struct sfs_orbit *sorbit_array[ ORBITS ];
  1312. X                /* array of orbit structures */
  1313. X   static int x_int;        /* a dummy for initial setting of element */
  1314. X   
  1315. X   /***  Set up dummy int pointer for elements */
  1316. X
  1317. X   x_elements = &x_int;
  1318. X
  1319. X   /***  Allocate memory for Escape menu */
  1320. X
  1321. X   for ( c = 0; c < EM_TITLES; ++c )
  1322. X      {
  1323. X      if ( ( em_titles[ c ] = malloc( 64 ) ) == NULL)
  1324. X         {
  1325. X     bw_error( MEMERR_ESC );
  1326. X         }
  1327. X      }
  1328. X
  1329. #ifdef  OLD_DEBUG
  1330. X   fprintf( stderr, "escape menu is now initialized\n" );
  1331. #endif
  1332. X
  1333. X   /***  Send initializing message on status/help line */
  1334. X
  1335. X   sfsx_help( SFSX_INIT );
  1336. X
  1337. X   /***  Set up default values in case they are not read 
  1338. X     by the program file. */
  1339. X
  1340. X   for ( orbit = 0; orbit < ORBITS; ++orbit )
  1341. X      {
  1342. X      sorbit_array[ orbit ] = NULL;      /* set all orbits to NULL */
  1343. X      }
  1344. X
  1345. X   sfs_tfactor = 1;                     /* default time factor = 1 (real time) */
  1346. X   sfs_inc = 120;                       /* default display update = 120
  1347. X                       seconds (2 minutes) */
  1348. X   sfs_insertion = 0;                   /* default insertion point = 0 seconds */
  1349. X
  1350. X   /***  Interpret the program file */
  1351. X
  1352. X   if ( sfs_pr( program, pr_name, sorbit_array, ORBITS ) == BW_ERROR )
  1353. X      {
  1354. X      sprintf( sfsx_tbuf, SFSX_PRERR, program );
  1355. X      bw_error( sfsx_tbuf );
  1356. X      sfs_exit( );
  1357. X      exit( 1 );
  1358. X      }   
  1359. #ifdef  OLD_DEBUG
  1360. X   else
  1361. X      {
  1362. X      sprintf( sfsx_tbuf, "Successfully interpreted program file <%s>", program );
  1363. X      bw_debug( sfsx_tbuf );
  1364. X      }
  1365. #endif
  1366. X
  1367. X   /***  Set up program screen */
  1368. X
  1369. X   cp_prog( program );
  1370. X
  1371. X   /***  Initialize displays */
  1372. X
  1373. X   di_init( sorbit_array, ORBITS, &x_displays, &n_displays, &t_array );
  1374. X
  1375. X   /***  Set initial elements to toggle */
  1376. X
  1377. X   x_elements = sfsx_curel();
  1378. X
  1379. #ifdef  OLD_DEBUG
  1380. X   for ( c = 0; c < n_displays; ++c )
  1381. X      {
  1382. X      sprintf( sfsx_tbuf, "Display title %d: %s", c, t_array[ c ] );
  1383. X      bw_debug( sfsx_tbuf );
  1384. X      }
  1385. #endif
  1386. X
  1387. X   /***  find first visual display, and set zoom and upper windows to it */
  1388. X
  1389. X   c = 0;
  1390. X   x_continue = TRUE;
  1391. X   while( ( c < n_displays ) && ( x_continue == TRUE ))
  1392. X      {
  1393. X      if ( x_displays[ c ]->type == SFSD_VISUAL )
  1394. X     {
  1395. X     d_zoom = c;
  1396. X     d_upper = c;
  1397. X     x_continue = FALSE;
  1398. X     }
  1399. X      ++c;
  1400. X      }
  1401. X
  1402. X   /***  find first ground track display, and set lower window to it */
  1403. X
  1404. X   c = 0;
  1405. X   x_continue = TRUE;
  1406. X   while( ( c < n_displays ) && ( x_continue == TRUE ))
  1407. X      {
  1408. X      if ( x_displays[ c ]->type == SFSD_GROUND )
  1409. X     {
  1410. X     d_lower = c;
  1411. X     x_continue = FALSE;
  1412. X     }
  1413. X      ++c;
  1414. X      }
  1415. X
  1416. X   /***  Read spd files for all active orbits */
  1417. X
  1418. X   for ( c = 0; c < ORBITS; ++c )
  1419. X      {
  1420. X      if ( sorbit_array[ c ] != NULL )
  1421. X     {
  1422. X
  1423. X     /* first read orb file for this orbit */
  1424. X
  1425. X     spj_readspd( sorbit_array[ c ]->orbfile,
  1426. X        &(sorbit_array[ c ]->o_start), &(sorbit_array[ c ]->o_end) );
  1427. X
  1428. X     /* read grid file for this orbit */
  1429. X
  1430. X     spj_readspd( sorbit_array[ c ]->gridfile,
  1431. X        &(sorbit_array[ c ]->g_start), &(sorbit_array[ c ]->g_end) );
  1432. X
  1433. X     /* read surface data file for this orbit */
  1434. X
  1435. X     spj_readspd( sorbit_array[ c ]->surfile,
  1436. X        &(sorbit_array[ c ]->s_start), &(sorbit_array[ c ]->s_end) );
  1437. X
  1438. X     /* read point data file for this orbit */
  1439. X
  1440. #ifdef  USEPOINTS
  1441. X     spj_readspd( sorbit_array[ c ]->pdfile,
  1442. X        &(sorbit_array[ c ]->p_start), &(sorbit_array[ c ]->p_end) );
  1443. #endif
  1444. X
  1445. X     }
  1446. X      }
  1447. X
  1448. X   /***  Send help message */
  1449. X
  1450. X   sfsx_help( SFSX_HELP );
  1451. X
  1452. X   /***  Initialize ground track and forward track for each orbit */
  1453. X
  1454. X   for ( orbit = 0; orbit < ORBITS; ++orbit )
  1455. X      {
  1456. X      if ( sorbit_array[ orbit ] != NULL )
  1457. X         {
  1458. X
  1459. X     /***  Initialize ground track system */
  1460. X
  1461. X     gt_init( sorbit_array, orbit  );
  1462. X
  1463. X     /***  Initialize the forward orbital track */
  1464. X
  1465. X     ft_init( sorbit_array, orbit, sfsx_poll );
  1466. X
  1467. X         }
  1468. X      }
  1469. X
  1470. X   /***  Poll to allow early exit with escape key */
  1471. X
  1472. X   sfsx_poll();
  1473. X
  1474. X   x_target = sfsx_getmet();            /* initialize mission elapsed time */
  1475. X
  1476. X   /***  Main Program Loop */
  1477. X
  1478. X   x_continue = TRUE;
  1479. X   while( x_continue == TRUE )
  1480. X      {
  1481. X
  1482. X      /***  1. See if a new focus and/or orbit needs to be set up */
  1483. X      /***     This is a stub presently, but will eventually allow */
  1484. X      /***     "true" space flight, i.e., the ability to switch to */
  1485. X      /***     a transfer orbit, and eventually to another orbital */
  1486. X      /***     focus. */
  1487. X
  1488. X      sfsx_poll();
  1489. X
  1490. X      /***  2.  Perform necessary calculations */
  1491. X      /***  2a. first calculate the current orbital positions
  1492. X        (subsatellite points) and update ground tracks */
  1493. X
  1494. #ifdef  OLD_DEBUG
  1495. X      sprintf( sfsx_tbuf, "[pr:] main(): orbit %d, focus %s, mass %le",
  1496. X     x_current, sorbit_array[ x_current ]->aorbit->focus->name,
  1497. X     sorbit_array[ x_current ]->aorbit->focus->mass );
  1498. X      bw_debug( sfsx_tbuf );
  1499. #endif
  1500. X
  1501. X      x_next = x_target + ( sfs_inc * sfs_tfactor );
  1502. X      for ( orbit = 0; orbit < ORBITS; ++orbit )
  1503. X         {
  1504. X         if ( sorbit_array[ orbit ] != NULL )
  1505. X            {
  1506. X        or_ssp( sorbit_array[ orbit ]->aorbit,
  1507. X           x_target, &(sorbit_array[ orbit ]->ssp_lat),
  1508. X           &(sorbit_array[ orbit ]->ssp_lon),
  1509. X           &(sorbit_array[ orbit ]->ssp_r),
  1510. X           &(sorbit_array[ orbit ]->ssp_n) );
  1511. #ifdef  OLD_DEBUG
  1512. X        sprintf( sfsx_tbuf, "main(): ssp, time %ld lat %.2lf lon %.2lf no %ld",
  1513. X               x_target, x_lat, x_lon, x_n );
  1514. X        bw_debug( sfsx_tbuf );
  1515. #endif
  1516. X        sprintf( sfsx_tbuf, "Updating ground track, orbit %d", orbit + 1 );
  1517. X        bw_message( sfsx_tbuf );
  1518. X            gt_update( x_target, sorbit_array, ORBITS );       /* Update Ground Track */
  1519. #ifdef    OLD_DEBUG
  1520. X            bw_debug( "return from gt_update()" );
  1521. #endif
  1522. X        sfsx_poll();
  1523. X
  1524. X            /***  2b. calculate the next orbital position to allow
  1525. X                    the rotation to be set appropriately */
  1526. X
  1527. X        or_ssp( sorbit_array[ orbit ]->aorbit,
  1528. X           x_next, &(sorbit_array[ orbit ]->nssp_lat),
  1529. X           &(sorbit_array[ orbit ]->nssp_lon),
  1530. X           &(sorbit_array[ orbit ]->nssp_r),
  1531. X           &(sorbit_array[ orbit ]->nssp_n) );
  1532. #ifdef  OLD_DEBUG
  1533. X        sprintf( sfsx_tbuf, "main(): next ssp, lat %.2lf lon %.2lf",
  1534. X               nssp_lat, nssp_lon );
  1535. X        bw_debug( sfsx_tbuf );
  1536. #endif
  1537. X
  1538. X        sfsx_poll();
  1539. X
  1540. X            /***  2c. calculate the rotation based on the current position
  1541. X                    and the next position */
  1542. X
  1543. X        sorbit_array[ orbit ]->ssp_rot =
  1544. X           vi_rotate( sorbit_array[ orbit ]->ssp_lon,
  1545. X           sorbit_array[ orbit ]->ssp_lat,
  1546. X           sorbit_array[ orbit ]->nssp_lon,
  1547. X           sorbit_array[ orbit ]->nssp_lat );
  1548. X
  1549. #ifdef  OLD_DEBUG
  1550. X        sprintf( sfsx_tbuf, "main(): rotation = %.2lf deg",
  1551. X               x_rot );
  1552. X        bw_debug( sfsx_tbuf );
  1553. #endif
  1554. X
  1555. X        sfsx_poll();
  1556. X        }
  1557. X     }
  1558. X
  1559. X      /***  2d. calculate perspective points */
  1560. X
  1561. X      pe_calc( sorbit_array, ORBITS, sfsx_poll );
  1562. X      sfsx_poll();
  1563. X
  1564. X      /***      calculations for each orbit */
  1565. X
  1566. X      for ( orbit = 0; orbit < ORBITS; ++orbit )
  1567. X     {
  1568. X     if ( sorbit_array[ orbit ] != NULL )
  1569. X        {
  1570. X
  1571. X        /***  2d+. calculate forward track */
  1572. X
  1573. X        ft_calc( x_target, sorbit_array, orbit, sfsx_poll );
  1574. X
  1575. X        /***  2e. calculate positions for the surface data */
  1576. X
  1577. X        sprintf( sfsx_tbuf, CALCSD, orbit + 1 );
  1578. X        bw_message( sfsx_tbuf );
  1579. X        spj_calc( &( sorbit_array[ orbit ]->s_start ), 
  1580. X               &( sorbit_array[ orbit ]->s_end ), 
  1581. X           sorbit_array[ orbit ]->ssp_lat,
  1582. X           sorbit_array[ orbit ]->ssp_lon,
  1583. X           (double) sorbit_array[ orbit ]->ssp_r,
  1584. X           sorbit_array[ orbit ]->aorbit->focus->radius,
  1585. X           sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll );
  1586. X        sfsx_poll();
  1587. X
  1588. X        /***  2f. calculate positions for the point data */
  1589. X
  1590. #ifdef  USEPOINTS
  1591. X        sprintf( sfsx_tbuf, "Calculating point data points for orbit %d",
  1592. X           orbit + 1 );
  1593. X        bw_message( sfsx_tbuf );
  1594. X        spj_calc( &( sorbit_array[ orbit ]->p_start ), 
  1595. X               &( sorbit_array[ orbit ]->p_end ), 
  1596. X           sorbit_array[ orbit ]->ssp_lat,
  1597. X           sorbit_array[ orbit ]->ssp_lon,
  1598. X           (double) sorbit_array[ orbit ]->ssp_r,
  1599. X           sorbit_array[ orbit ]->aorbit->focus->radius,
  1600. X           sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll );
  1601. X        sfsx_poll();
  1602. #endif
  1603. X
  1604. X        /***  2g. calculate positions for the grid data */
  1605. X
  1606. X        sprintf( sfsx_tbuf, CALCGR, orbit + 1 );
  1607. X        bw_message( sfsx_tbuf );
  1608. X        spj_calc( &( sorbit_array[ orbit ]->g_start ),
  1609. X               &( sorbit_array[ orbit ]->g_end ),
  1610. X               sorbit_array[ orbit ]->ssp_lat, 
  1611. X           sorbit_array[ orbit ]->ssp_lon,
  1612. X           (double) sorbit_array[ orbit ]->ssp_r,
  1613. X           sorbit_array[ orbit ]->aorbit->focus->radius,
  1614. X           sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll );
  1615. X        sfsx_poll();
  1616. X
  1617. X        /***  2h. calculate positions for the orb. Note that the
  1618. X              orb has to be shown from viewer latitude 0.0,
  1619. X              longitude 0.0 */
  1620. X
  1621. X        sprintf( sfsx_tbuf, CALCORB, orbit + 1 );
  1622. X        bw_message( sfsx_tbuf );
  1623. X        spj_calc( &( sorbit_array[ orbit ]->o_start ),
  1624. X               &( sorbit_array[ orbit ]->o_end ), 
  1625. X               0.0, 0.0, (double) sorbit_array[ orbit ]->ssp_r,
  1626. X           sorbit_array[ orbit ]->aorbit->focus->radius,
  1627. X           sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll );
  1628. X        sfsx_poll();
  1629. X
  1630. X        }
  1631. X     }
  1632. X
  1633. X      /***  3. Wait until time for next display */
  1634. X
  1635. X      bw_message( SFSX_WAIT );
  1636. X      sfsx_poll();
  1637. X      while( sfsx_getmet() < x_target )
  1638. X     {
  1639. #ifdef  OLD_DEBUG
  1640. X     sprintf( sfsx_tbuf, "wait: %ld / %ld", sfsx_getmet(), x_target );
  1641. X     bw_message( sfsx_tbuf );
  1642. #endif
  1643. X     sfsx_poll();
  1644. X     }
  1645. X
  1646. X      /***  4. Update the simulation display */
  1647. X
  1648. #ifdef  OLD_DEBUG
  1649. X      sprintf( sfsx_tbuf, "call update() display %d, n %d, orbit_n %ld",
  1650. X     x_display, ORBITS, x_n );
  1651. X      bw_debug( sfsx_tbuf );
  1652. X      sprintf( sfsx_tbuf, "call update() lat %.1lf lon %.1lf, rad %.1lf dis %.1lf",
  1653. X     x_lat, x_lon,
  1654. X     sorbit_array[ x_current ]->aorbit->focus->radius,
  1655. X     (double) x_r );
  1656. X      bw_debug( sfsx_tbuf );
  1657. X      sprintf( sfsx_tbuf, "call update() focal radius %.1lf",
  1658. X     sorbit_array[ 0 ]->aorbit->focus->radius );
  1659. X      bw_debug( sfsx_tbuf );
  1660. X      sfsx_test( x_display, ORBITS, x_lat, x_lon,
  1661. X     sorbit_array[ x_current ]->aorbit->focus->radius,
  1662. X     (double) x_r, x_n, sorbit_array );
  1663. #endif
  1664. X
  1665. X      sfsx_update( ORBITS,
  1666. X         sorbit_array, x_displays, n_displays, x_target,
  1667. X         x_zoom, d_zoom, d_upper, d_lower );
  1668. X
  1669. X      /***  display is initialized */
  1670. X
  1671. X      x_init = TRUE;
  1672. X
  1673. X      /***  5. Set the next target time */
  1674. X
  1675. X      x_target += ( sfs_inc * sfs_tfactor );
  1676. X
  1677. #ifdef  BLOCKEDOUT
  1678. X      bw_message( "end of main loop cycle: ESCAPE to exit" );
  1679. X      if ( kb_rx() == 0x1b )
  1680. X     {
  1681. X     sfs_exit();
  1682. X     }
  1683. #endif
  1684. X
  1685. X      }
  1686. X
  1687. X   }
  1688. X
  1689. /****************************************************************
  1690. X
  1691. X    sfs_exit()             Exit from Simulation Module
  1692. X
  1693. ****************************************************************/
  1694. X
  1695. sfs_exit()
  1696. X   {
  1697. /*   gr_cls( GR_PRIMARY ); */
  1698. X   if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != NULL )
  1699. X      {
  1700. X      fprintf( data, "%s %s %s\n", SFSCH_MODEL, pr_file, SFS_CONTARG );
  1701. X      fclose( data );
  1702. X      }
  1703. X   else
  1704. X      {
  1705. X      fprintf( stderr, ERR_CHAIN );
  1706. X      }
  1707. X   gr_deinit();
  1708. X   exit( 0 );
  1709. X   }
  1710. X
  1711. /****************************************************************
  1712. X
  1713. X    sfsx_colors()           Initialize Colors for Simulation
  1714. X
  1715. ****************************************************************/
  1716. X
  1717. sfsx_colors()
  1718. X   {
  1719. X   register int c;
  1720. X   int n;
  1721. X
  1722. X   if ( gr_colors > 8 )
  1723. X      {
  1724. X      cl_mback = WHITE;
  1725. X      cl_mfore = BLACK;
  1726. X      cl_marker = DARK_CYAN;
  1727. X      cl_grid = DARK_BLUE;
  1728. X      cl_surface = DARK_GREEN;
  1729. X      n = LIGHT_RED;
  1730. X      for ( c = 0; c < OR_COLORS; ++c )
  1731. X         {
  1732. X         cl_orbits[ c ] = n;
  1733. X         ++n;
  1734. X         }
  1735. X      }
  1736. X   else if ( gr_colors > 2 )
  1737. X      {
  1738. X      cl_mback = WHITE;
  1739. X      cl_mfore = BLACK;
  1740. X      cl_marker = BLACK;
  1741. X      cl_grid = WHITE;
  1742. X      cl_surface = WHITE;
  1743. X      for ( c = 0; c < OR_COLORS; ++c )
  1744. X         {
  1745. X         cl_orbits[ c ] = WHITE;
  1746. X         }
  1747. X      }
  1748. X   else
  1749. X      {
  1750. X      cl_mback = WHITE;
  1751. X      cl_mfore = BLACK;
  1752. X      cl_marker = WHITE;
  1753. X      cl_grid = WHITE;
  1754. X      cl_surface = WHITE;
  1755. X      for ( c = 0; c < OR_COLORS; ++c )
  1756. X         {
  1757. X         cl_orbits[ c ] = WHITE;
  1758. X         }
  1759. X      }
  1760. X
  1761. X   }
  1762. X
  1763. /****************************************************************
  1764. X
  1765. X    sfsx_poll()
  1766. X
  1767. ****************************************************************/
  1768. X
  1769. sfsx_poll()
  1770. X   {
  1771. X   register int c;
  1772. X   static int x, y, b;
  1773. X
  1774. X   /* Check for keyboard input */
  1775. X
  1776. X   while ( kb_rxstat() == TRUE )
  1777. X      {
  1778. X      c = kb_rx();
  1779. X      if ( c == 0x1b )
  1780. X         {
  1781. X     sfsx_esc();
  1782. X         x_elements = sfsx_curel();
  1783. X         }
  1784. X      else
  1785. X         {
  1786. X     el_toggle( c, x_elements );
  1787. X     if ( x_init == TRUE )
  1788. X        {
  1789. X        el_show( GR_PRIMARY, e_wind, *x_elements );
  1790. X        }
  1791. X         }
  1792. X      }
  1793. X
  1794. X   /* Check for mouse input */
  1795. X
  1796. X   if ( gr_ismouse == TRUE )
  1797. X      {
  1798. X      if ( gr_mouse( SAMPLE, &x, &y, &b ) == TRUE )
  1799. X     {
  1800. X
  1801. X     gr_mouse( WAIT, &x, &y, &b );           /* click down */
  1802. X     gr_mouse( WAIT, &x, &y, &b );           /* click up */
  1803. X
  1804. #ifdef  OLD_DEBUG
  1805. X     sprintf( sfsx_tbuf, "Mouse hit: %d %d", x, y );
  1806. X     bw_debug( sfsx_tbuf );
  1807. #endif
  1808. X
  1809. X     /* Is the release within bounds ? */
  1810. X
  1811. X     if ( uil_bounds( x, y, main_window->tbar_x1, main_window->tbar_y1,
  1812. X        main_window->tbar_x2, main_window->tbar_y2) == TRUE )
  1813. X        {
  1814. X        sfsx_esc();
  1815. X        }
  1816. X
  1817. X     }
  1818. X      }
  1819. X   }
  1820. X
  1821. /****************************************************************
  1822. X
  1823. X    sfsx_esc()
  1824. X
  1825. ****************************************************************/
  1826. X
  1827. sfsx_esc()
  1828. X   {
  1829. X   int c;
  1830. X   static struct menu_box esc_box;
  1831. X   int y, test;
  1832. X   static int x_x1 = 0, x_y1 = 0, x_x2 = 0, x_y2 = 0, item;
  1833. X   static int x_ebuf;
  1834. X   
  1835. X   ui_push();                   /* save current ui screen */
  1836. X   ui_setscreen( GR_PRIMARY );  /* set primary screen */
  1837. X   if ( x_x1 == 0 )
  1838. X      {
  1839. X      x_x1 = (int) fo_xcenter - ( ui_grwind->xmax / 4 );
  1840. X      x_y1 = (int) fo_ycenter - ( ui_grwind->fysize * 7 );
  1841. X      x_x2 = (int) fo_xcenter + ( ui_grwind->xmax / 4 );
  1842. X      x_y2 = (int) fo_ycenter + ( ui_grwind->fysize * 5 );
  1843. X      }
  1844. X
  1845. X   strcpy( em_titles[ 0 ], ZOOMTITLE );
  1846. X   strcpy( em_titles[ 1 ], UPPERTITLE );
  1847. X   strcpy( em_titles[ 2 ], LOWERTITLE );
  1848. X   strcpy( em_titles[ 3 ], SYSTITLE );
  1849. X   strcpy( em_titles[ 4 ], ABORTTITLE );
  1850. X   strcpy( em_titles[ 5 ], EXITTITLE );
  1851. X
  1852. X   gr_imsave( GR_PRIMARY, TRUE, x_x1, x_y1, x_x2, x_y2, &x_ebuf );
  1853. X
  1854. X   sfsx_help( SFSX_MM );
  1855. X
  1856. X   esc_box.is_drawn = FALSE;
  1857. X   item = ui_list( MENU_SLIDERS, x_x1, x_y1, x_x2, x_y2,
  1858. X      ESCTITLE, EM_TITLES,
  1859. X      em_titles, cl_mfore, cl_mback, cl_marker,
  1860. X      &esc_box );
  1861. X
  1862. X   gr_imsave( GR_PRIMARY, FALSE, x_x1, x_y1, x_x2, x_y2, &x_ebuf );
  1863. X   gr_imfree( x_ebuf );
  1864. X   sfsx_help( SFSX_HELP );
  1865. X
  1866. X   switch( item )
  1867. X      {
  1868. X      case 0:
  1869. X     d_zoom = sdi( t_array, n_displays, ZOOMTITLE );
  1870. X     x_zoom = TRUE;
  1871. X     break;
  1872. X      case 1:
  1873. X     d_upper = sdi( t_array, n_displays, UPPERTITLE );
  1874. X     x_zoom = FALSE;
  1875. X         break;
  1876. X      case 2:
  1877. X     d_lower = sdi( t_array, n_displays, LOWERTITLE );
  1878. X     x_zoom = FALSE;
  1879. X         break;
  1880. X      case 3:
  1881. X         ssp();
  1882. X     break;
  1883. X      case 4:
  1884. X     if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != NULL )
  1885. X        {
  1886. X        fprintf( data, "%s\n", SFS_EXITARG );
  1887. X        fclose( data );
  1888. X        }
  1889. X     else
  1890. X        {
  1891. X        fprintf( stderr, ERR_CHAIN );
  1892. X        }
  1893. X     gr_deinit();
  1894. X     exit( 0 );
  1895. X     break;
  1896. #ifdef  ABORT_ON_ESCAPE
  1897. X      case TK_EXIT:
  1898. #endif
  1899. X      case 5:
  1900. X     sfs_exit();
  1901. X     exit(0);
  1902. X      default:
  1903. X         break;
  1904. X      }
  1905. X
  1906. X   ui_pop();                            /* restore ui screen */
  1907. X
  1908. X   }
  1909. X
  1910. /****************************************************************
  1911. X
  1912. X    sfsx_getmet()           Get Mission Elapsed Time
  1913. X
  1914. ****************************************************************/
  1915. X
  1916. long
  1917. sfsx_getmet()
  1918. X   {
  1919. X   static int x_initialized = FALSE;
  1920. X   static time_t x_now;
  1921. X
  1922. X   if ( x_initialized == FALSE )
  1923. X      {
  1924. X      x_initialized = TRUE;
  1925. X      x_now = time( NULL );
  1926. X      sfsx_epoch = x_now;
  1927. #ifdef  OLD_DEBUG
  1928. X      sprintf( sfsx_tbuf, "sfs_getmet(): epoch = %ld", sfsx_epoch );
  1929. X      bw_debug( sfsx_tbuf );
  1930. #endif
  1931. X      return (long) sfs_insertion;
  1932. X      }
  1933. X
  1934. X   x_now = time( NULL );
  1935. X   return (long) ( ( ( x_now + sfs_insertion ) - sfsx_epoch ) * sfs_tfactor );
  1936. X   }
  1937. X
  1938. #ifdef  OLD_DEBUG
  1939. sfsx_test( display, n, lat, lon, radius, distance, orbit_n, sorbit_array )
  1940. SHAR_EOF
  1941. true || echo 'restore of sfs/sfs/sfsx.c failed'
  1942. fi
  1943. echo 'End of  part 20'
  1944. echo 'File sfs/sfs/sfsx.c is continued in part 21'
  1945. echo 21 > _shar_seq_.tmp
  1946. exit 0
  1947. exit 0 # Just in case...
  1948. -- 
  1949. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1950. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1951. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1952. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1953.